#include <unittest++/UnitTest++.h>

#include <string>
#include "srtsubtitle.h"

using std::string;

SUITE(SrtSubtitleTest)
{
    TEST(TestReadSubtitle)
    {
        SrtSubtitle sub("../data/testdata/testsubtitle.srt");
        //CHECK_EQUAL(2, sub.m_Subtitles.size());
        
        SubtitleEntity subEntity1;
        CHECK(sub.getSubtitle(137500, subEntity1));
        CHECK_EQUAL(1, subEntity1.index);
        CHECK_EQUAL(137440, subEntity1.startTime);
        CHECK_EQUAL(140375, subEntity1.endTime);
        CHECK_EQUAL("FirstSubtitle line 1", subEntity1.line1);
        CHECK_EQUAL("FirstSubtitle line 2", subEntity1.line2);
        
        SubtitleEntity subEntity2;
        CHECK(sub.getSubtitle(140500, subEntity2));
        CHECK_EQUAL(2, subEntity2.index);
        CHECK_EQUAL(140476, subEntity2.startTime);
        CHECK_EQUAL(142501, subEntity2.endTime);
        CHECK_EQUAL("SecondSubtitle line 1", subEntity2.line1);
        CHECK(subEntity2.line2.empty());
        
        SubtitleEntity subEntity3;
        CHECK(!sub.getSubtitle(0, subEntity3));
    }
    
    TEST(TestReadSubtitleNotExists)
    {
        CHECK_THROW(SrtSubtitle sub("invalid.srt"), SubtitleException);
    }
}
